package wwk.com.android_meilishuo.mvp.presenter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import wwk.com.android_meilishuo.mvp.model.HomeHeadBiz;
import wwk.com.android_meilishuo.mvp.model.MLSModel;
import wwk.com.android_meilishuo.mvp.view.MLSView;
import wwk.com.android_meilishuo.ui.home.adapter.ChannelAdapter;
import wwk.com.android_meilishuo.ui.home.adapter.TrendAdapter;
import wwk.com.android_meilishuo.ui.home.bean.ChannelBean;
import wwk.com.android_meilishuo.ui.home.bean.FashionTitleBean;
import wwk.com.android_meilishuo.ui.home.bean.ListBean;
import wwk.com.android_meilishuo.ui.home.bean.TrendBean;

/**
 * Created by Administrator on 2017/1/4.
 */

public class HomePresenter {
    private MLSModel.IHomeHeadBiz homeHeadBiz;
    private MLSView.IHomeChannelView homeView;

    public HomePresenter(MLSView.IHomeChannelView homeChannelView) {
        this.homeView = homeChannelView;
        this.homeHeadBiz = new HomeHeadBiz();
    }

    public void loadHomeData(final Context context, final List<ImageView> list_Beauty,
                             final ImageView imageView_home_trend_title, final List<TextView> list_Trend) {
        homeHeadBiz.loadHomeHeadData(new MLSModel.OnHomeHeadListener() {
            @Override
            public void onHeadSuccess(List<ChannelBean.ListBean> list) {
                if (list != null && list.size() != 0) {
                    ChannelAdapter adapter = new ChannelAdapter(context, list);
                    homeView.toSetAdapter(adapter);
                }

            }

            @Override
            public void onFashionSuccess(List<FashionTitleBean.ListBean> list) {
                for (int i = 0; i < list.size(); i++) {
                    Glide.with(context).load(list.get(0).getImage()).into(imageView_home_trend_title);
                }

            }

            @Override
            public void onFailed(Exception e) {
                homeView.showError(e);
            }
        }, context);

        homeHeadBiz.loadBeautyHeadData(new MLSModel.OnBeautyHeadListener() {

            @Override
            public void onBeautySuccess(List<ListBean> list) {
                for (int i = 0; i < list_Beauty.size(); i++) {
                    Glide.with(context).load(list.get(i).getImage()).into(list_Beauty.get(i));
                }
            }

            @Override
            public void onFailed(Exception e) {

            }
        }, context);

        homeHeadBiz.loadTrendHeadData(new MLSModel.OnTrendHeadListener() {
            @Override
            public void onTrendSuccess(List<TrendBean.DataBean.ListBean> list, TrendBean.DataBean.TomorrowAdvanceBean tomorrowBean) {
                TrendAdapter adapter = new TrendAdapter(context, list);
                homeView.toSetTrendAdapter(adapter);
                for (int i = 0; i < list_Trend.size(); i++) {
                    list_Trend.get(0).setText(tomorrowBean.getAdvanceTag());
                    list_Trend.get(1).setText(tomorrowBean.getAdvanceTime());
                    list_Trend.get(2).setText(tomorrowBean.getAdvanceTitle());
                }
            }

            @Override
            public void onFailed(Exception e) {
                homeView.showError(e);
            }
        }, context);
    }
}
